#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@IDE     ：PyCharm 
@Author  ：kiway
@Date    ：2024/7/27 11:09 
"""

from typing import Any, Callable, List

EVENT_TIMER = "eTimer"
EVENT_BAR = "eBar"
EVENT_TICK = "eTick"
EVENT_ORDERBOOK = "eOrderbook"
EVENT_PrORDER = "ePOrder"  # 风控前的订单，还需要过完风控才可以去执行
EVENT_PsORDER = "ePsOrder"  # 风控后的订单，可以直接请求交易所去执行
EVENT_TRADE = "eTrade"
EVENT_CROSSBAR = "eCrossBar"
EVENT_AGGTRADE = "eAggTrade"
EVENT_POSITIONS_UPDATE = "ePositionsUpdate"
EVENT_BALANCE_UPDATE = "eBalanceUpdate"
EVENT_ORDER_STATUS_UPDATE = "eOrderStatusUpdate"
EVENT_SWITCH = "eSwitch"  # 截面切换信号
EVENT_POLYBAR = "ePolyBar"  # 截面数据信号


class Event:
    """
    Event object consists of a type string which is used
    by event engine for distributing event, and a data
    object which contains the real data.
    """

    def __init__(self, type: str, data: Any = None) -> None:
        """"""
        self.type: str = type
        self.data: Any = data

    def __repr__(self):
        return self.type


# Defines handler function to be used in event engine.
# HandlerType: coroutine = coroutine


class MarketEvent(Event):

    def __init__(self, symbol, data, exchange, type):
        self.symbol = symbol
        self.exchange = exchange
        super().__init__(type=type, data=data)


class BarEvent(MarketEvent):

    def __init__(self, symbol, data, exchange):
        super().__init__(symbol=symbol, exchange=exchange, type=EVENT_BAR, data=data)


class OrderBookEvent(MarketEvent):

    def __init__(self, symbol, data, exchange):
        super().__init__(symbol=symbol, exchange=exchange, type=EVENT_ORDERBOOK, data=data)


class TickEvent(MarketEvent):

    def __init__(self, symbol, data, exchange):
        super().__init__(symbol=symbol, exchange=exchange, type=EVENT_TICK, data=data)


class TradeEvent(MarketEvent):
    def __init__(self, symbol, data, exchange):
        super().__init__(symbol=symbol, exchange=exchange, type=EVENT_TRADE, data=data)


class AggTradeEvent(MarketEvent):
    def __init__(self, symbol, data, exchange):
        super().__init__(symbol=symbol, exchange=exchange, type=EVENT_AGGTRADE, data=data)


class PrOrderEvent(Event):
    def __init__(self, symbol, data, exchange_id):
        self.symbol = symbol
        self.exchange_id = exchange_id
        super().__init__(EVENT_PrORDER, data)


class PsOrderEvent(Event):
    def __init__(self, symbol, data, exchange):
        self.symbol = symbol
        self.exchange_id = exchange
        super().__init__(EVENT_PsORDER, data)


class CrossBarEvent(Event):

    def __init__(self, data: Any = None):
        super().__init__(EVENT_CROSSBAR, data)


class PositionsEvent(Event):

    def __init__(self, data):
        super().__init__(EVENT_POSITIONS_UPDATE, data)


class BalanceEvent(Event):

    def __init__(self, data):
        super().__init__(EVENT_BALANCE_UPDATE, data)


class OrderStatusEvent(Event):

    def __init__(self, data):
        super().__init__(EVENT_ORDER_STATUS_UPDATE, data)


class SwitchEvent(Event):

    def __init__(self, data=None):
        super().__init__(EVENT_SWITCH, data)


class PolyBarEvent(Event):
    def __init__(self, symbol, is_future, data):
        super().__init__(EVENT_POLYBAR, data)
        self.symbol = symbol
        self.is_future = is_future